<template>
  <el-main>
    <el-form ref="form" :model="form" label-width="80px" inline>
      <el-form-item label="申请状态">
        <el-select v-model="form.applyState" placeholder="请选择">
          <el-option label="待审核" value="1"></el-option>
          <el-option label="初审通过(待复审)" value="2"></el-option>
          <el-option label="初审不通过" value="3"></el-option>
          <el-option label="复审通过" value="4"></el-option>
          <el-option label="复审不通过" value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="查询日期">
        <el-col :span="11">
          <el-date-picker type="date" v-model="form.startDate" style="width:120px" value-format="yyyy-MM-dd"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">{{"\xa0"}}至</el-col>
        <el-col :span="11">
          <el-date-picker type="date" v-model="form.endDate" style="width:120px" value-format="yyyy-MM-dd"></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button @click="onEmpty">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table
      border
      :data="tableData">
      <el-table-column
        prop="factoringOrderNo"
        label="租约保理申请单号"
        width="200"
        align="center">
      </el-table-column>
      <el-table-column
        prop="loanAmount"
        label="借款金额"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        prop="monthLimit"
        label="借款期限"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        prop="rentMoney"
        label="应收租约合计"
        width="120"
        align="center">
      </el-table-column>
      <el-table-column
        prop="factoringCreditMoney"
        label="保理授信金额合计"
        width="140"
        align="center">
      </el-table-column>
      <el-table-column
        prop="factoringAdditionalMoney"
        label="保理利息合计"
        width="120"
        align="center">
      </el-table-column>
      <el-table-column
        prop="factoringTrueMoney"
        label="实收保理金额"
        width="120"
        align="center">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建用户时间"
        width="120"
        align="center">
      </el-table-column>
      <el-table-column
        prop="auditMemo"
        label="审核备注"
        width="90"
        align="center">
      </el-table-column>
      <el-table-column
        prop="applyState"
        label="申请类型"
        width="140"
        align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.applyState==1">待审核</span>
          <span v-if="scope.row.applyState==2">初审通过(待复审)</span>
          <span v-if="scope.row.applyState==3">初审不通过</span>
          <span v-if="scope.row.applyState==4">复审通过</span>
          <span v-if="scope.row.applyState==5">复审不通过</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="100"
        align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.applyState==1 || scope.row.applyState==2"><el-button type="text" style="color:sandybrown" @click="toAudit(scope.row)">审核</el-button></span>
          <span v-if="scope.row.applyState==3 || scope.row.applyState==4 || scope.row.applyState==5"><el-button type="text" style="color:sandybrown" @click="toAudit(scope.row)">查看</el-button></span>
          <span v-if="scope.row.applyState==null"><el-button type="text" style="color:sandybrown" @click="toAudit(scope.row)">放款成功</el-button></span>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" align="center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.form.pageNum"
        :page-sizes="[5,10]"
        :page-size="this.form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </el-main>
</template>

<script>
import {factoringList} from "@/api/banking/leasefactoringreview";
export default {
  data() {
    return {
      tableData: [],
      form: {
        pageNum:1,
        pageSize:10,
        applyState:'',
        startDate:'',
        endDate:'',
      },
      total:0,
    }
  },
  methods: {
    getFactoringList(){
      factoringList(this.form).then(res=>{
        console.log(res);
        this.tableData = res.msgData.list;
        this.total = res.msgData.total;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.form.pageSize = val;
      this.form.pageNum = 1;
      this.getFactoringList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.form.pageNum = val;
      this.getFactoringList();
    },
    //清空
    onEmpty(){
      this.form = {
        pageNum:1,
        pageSize:10,
        jrProductType:'',
        applyState:'',
        startDate:'',
        endDate:'',
      }
    },
    //查询
    onSubmit(){
      console.log(this.form)
      this.getFactoringList();
    },
    //去审核 查看 放款成功
    toAudit(row){
        console.log(row);
        this.$router.push({
            path:"/banking/leasefactoringreview/lookover",
            query:{
              id:row.id, //t_jr_rent_installment表的id租房分期申请的id
              factoringOrderNo:row.factoringOrderNo,//租约保理申请单号
              jrProductId:row.jrProductId,//申请产品id
              applyState:row.applyState,//申请状态
            }
        })
    }
  },
  created() {
    this.getFactoringList();
  }
}
</script>

<style scoped>

</style>
